package tw.com.softleader.spring.service;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import tw.com.softleader.spring.model.Book;

public class BookService implements ApplicationContextAware {
	
	private Logger log = LoggerFactory.getLogger(this.getClass()); 

	private ApplicationContext applicationContext;
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.applicationContext = applicationContext;
		
	}
	
	
	public List<Book> getAll() {
		
		List<Book> books = new ArrayList<Book>();
		
		
		Book book1 = (Book) applicationContext.getBean("book");
		book1.setIsbnNo("AAA-001");
		book1.setName("A");
		book1.setPrice("100");
		
		Book book2 = (Book) applicationContext.getBean("book");
		book2.setIsbnNo("BBB-001");
		book2.setName("B");
		book2.setPrice("200");
		
		log.debug("{}", book1);
		
		log.debug("{}", book2);
		
		
		
		return books;
		
	}


	
}
